package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcOrdgroupEntity;
import com.dhcc.cdc.busi.service.ICdcOrdgroupService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 医嘱套(组)
 * 
 * @ClassName: CdcOrdgroupController
 * @Description: TODO
 * @author jumper
 * @date 2021-03-15 10:20:07
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/cdcordgroup")
public class CdcOrdgroupController extends BaseController {

	private String PREFIX = "/backend/cdc/cdcordgroup/";

	@Autowired
	private ICdcOrdgroupService cdcOrdgroupService;
	

    /**
     * 跳转到医嘱套(组)列表首页
     */
    @RequestMapping("")
    @Permission("cdcordgroup:list")
    public String index() {
        return PREFIX + "cdcordgroup.html";
    }
	
    /**
     * 跳转到新增医嘱套(组)
     */
    @RequestMapping("/to_add")
    @Permission("cdcordgroup:add")
    public String toAdd() {
        return PREFIX + "cdcordgroup_add.html";
    }
	
	/**
     * 跳转到修改医嘱套(组)
     */
    @RequestMapping("/to_update/{cdcOrdgroupId}")
    @Permission("cdcordgroup:update")
    public String toUpdate(@PathVariable Long cdcOrdgroupId, Model model) {
        CdcOrdgroupEntity cdcOrdgroup = this.cdcOrdgroupService.selectById(cdcOrdgroupId);
        model.addAttribute("cdcOrdgroup",cdcOrdgroup);
        return PREFIX + "cdcordgroup_edit.html";
    }

    @RequestMapping("/to_list")
    @Permission("cdcordgroup:update")
    public String toList() {
        return PREFIX + "cdcordgroup_list.html";
    }
    /**
     * 获取医嘱套(组)列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("cdcordgroup:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcOrdgroupEntity> page = new PageFactory<CdcOrdgroupEntity>().defaultPage();
        List<CdcOrdgroupEntity> result = this.cdcOrdgroupService.page(page,params);
        page.setRecords((List<CdcOrdgroupEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增医嘱套(组)
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("cdcordgroup:add")
    @BussinessLog(value = "新增医嘱套(组)")
    public Object add(CdcOrdgroupEntity cdcOrdgroup) {
        if (CommonUtil.isOneEmpty(cdcOrdgroup)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        cdcOrdgroup.insert();
        return R.ok();
    }

    /**
     * 删除医嘱套(组)
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("cdcordgroup:delete")
    @BussinessLog(value = "删除医嘱套(组)")
    public Object delete(@RequestParam Long cdcOrdgroupId) {
	
        this.cdcOrdgroupService.deleteById(cdcOrdgroupId);

        return R.ok();
    }

    /**
     * 修改医嘱套(组)
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("cdcordgroup:update")
    @BussinessLog(value = "修改医嘱套(组)")
    public Object update(CdcOrdgroupEntity cdcOrdgroup) {
        if (CommonUtil.isOneEmpty(cdcOrdgroup)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcOrdgroupEntity old = this.cdcOrdgroupService.selectById(cdcOrdgroup.getId());

        old.setXcode(cdcOrdgroup.getXcode());
        old.setCode(cdcOrdgroup.getCode());
        old.setDescription(cdcOrdgroup.getDescription());
        old.setDataId(cdcOrdgroup.getDataId());
        old.setIsActive(cdcOrdgroup.getIsActive());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
